package ding;

import work.config.Constant;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class WorkFileWriter {


    private static File sqlFile = new File(Constant.work, "插入.sql");

    private static BufferedWriter sqlWriter;


    public static void writeSqlLine(String sql) {
        try {
            sqlWriter.write(sql + "\n");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    static {

        try {
            if (!sqlFile.exists()) {
                sqlFile.createNewFile();
            }

            sqlWriter = new BufferedWriter(new FileWriter(sqlFile));

        } catch (IOException e) {
            e.printStackTrace();
        }

    }



    private static BufferedWriter errorWriter;

    private static File err = new File(Constant.work, "处理出错的文件.txt");
    static {

        if (!err.exists()) {
            try {
                err.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }


    static {
        try {
            errorWriter = new BufferedWriter(new FileWriter(err));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void writeErr(String msg) {
        try {
            errorWriter.write(msg + "\n");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void close() {


        try {
            errorWriter.flush();

            errorWriter.close();

            sqlWriter.flush();
            sqlWriter.close();
        } catch (Exception e) {

        }


    }


}
